#include <bits/stdc++.h>
#define re register
#define int long long

using namespace std;

mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
const int N = 2e5 + 10,M = N * 2,K = 24;
int n,q,lstans;
int idx,h[N],ne[M],e[M],w[M];
int lg[N],rt[N],dep[N],dis[N];
int tim,fp[N],sz[N],wson[N],dfn[N],pid[N],tp[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline void add(int a,int b,int c){
    ne[idx] = h[a];
    e[idx] = b,w[idx] = c;
    h[a] = idx++;
}

inline void dfs1(int u,int fa){
    dep[u] = dep[fp[u] = fa] + (sz[u] = 1);
    for (re int i = h[u];~i;i = ne[i]){
        int v = e[i];
        if (v == fa) continue;
        dis[v] = dis[u] + w[i];
        dfs1(v,u); sz[u] += sz[v];
        if (sz[v] > sz[wson[u]]) wson[u] = v;
    }
}

inline void dfs2(int u,int fa,int top){
    tp[pid[dfn[u] = ++tim] = u] = top;
    if (!wson[u]) return;
    dfs2(wson[u],u,top);
    for (re int i = h[u];~i;i = ne[i]){
        int v = e[i];
        if (v != fa && v != wson[u]) dfs2(v,u,v);
    }
}

inline int lca(int x,int y){
    while (tp[x] != tp[y]){
        if (dep[tp[x]] < dep[tp[y]]) y = fp[tp[y]];
        else x = fp[tp[x]];
    } return ((dep[x] < dep[y]) ? x : y);
}

struct{
    #define pot(x) (1 << (x))

    int dp1[N][K],dp2[N][K];

    inline void build(){
        for (re int i = 1;i <= n;i++) dp1[i][0] = dp2[i][0] = dfn[i];
        for (re int j = 1;j <= lg[n];j++){
            for (re int i = 1;i + pot(j) - 1 <= n;i++){
                dp1[i][j] = min(dp1[i][j - 1],dp1[i + pot(j - 1)][j - 1]);
                dp2[i][j] = max(dp2[i][j - 1],dp2[i + pot(j - 1)][j - 1]);
            }
        }
    }

    inline int querymin(int l,int r){
        int x = lg[r - l + 1];
        return min(dp1[l][x],dp1[r - pot(x) + 1][x]);
    }

    inline int querymax(int l,int r){
        int x = lg[r - l + 1];
        return max(dp2[l][x],dp2[r - pot(x) + 1][x]);
    }

    #undef pot
}st;

signed main(){
    freopen("memory.in","r",stdin);
    freopen("memory.out","w",stdout);
    memset(h,-1,sizeof(h));
    n = read(),q = read();
    for (re int i = 1,a,b,c;i < n;i++){
        a = read(),b = read(),c = read();
        add(a,b,c); add(b,a,c);
    } dfs1(1,0); dfs2(1,0,1);
    for (re int i = 2;i <= n;i++) lg[i] = lg[i >> 1] + 1;
    st.build();
    while (q--){
        int p = read() ^ lstans;
        int l = read() ^ lstans;
        int r = read() ^ lstans;
        // cerr << p << " " << l << " " << r << " ???\n";
        if (l <= p && p <= r) lstans = 0;
        else{
            int Min = st.querymin(l,r),Max = st.querymax(l,r);
            int gf = lca(pid[Min],pid[Max]);
            // cerr << l << " " << r << " " << Min << " " << Max << " " << gf << " ???\n";
            if (dfn[p] <= dfn[gf] && dfn[gf] <= dfn[p] + sz[p] - 1) lstans = dis[gf] - dis[p];
            else{
                int A = lca(pid[Min],p),B = lca(pid[Max],p);
                int nd = (dep[A] > dep[B]) ? A : B;
                uniform_int_distribution<int> rnt(l,r);
                for (re int _ = 1;_ <= 10;_++){
                    int x = lca(rnt(rnd),p);
                    if (dep[nd] < dep[x]) nd = x;
                }
                // cerr << nd << " " << A << " " << B << " ???\n";
                if (dep[nd] > dep[gf]) lstans = dis[p] - dis[nd];
                else lstans = dis[p] + dis[gf] - 2 * dis[nd];
            }
        } printf("%lld\n",lstans);
    }
    return 0;
}